package net.pimpas.report.processor.util;

import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;

import net.pimpas.report.processor.field.Field;
import net.pimpas.report.processor.field.impl.DefaultField;
import net.pimpas.util.reflection.ReflectionUtil;

public abstract class ProcessorUtils {
	
	public static Object[] getObjectValue( Object object, String fieldName) {
		try {
			PropertyDescriptor pd = ReflectionUtil.getPropertyDescriptor(object.getClass(), fieldName);
			if(pd == null) return null;
			Object value = pd.getReadMethod().invoke(object);
			return new Object[]{value};
		} catch (SecurityException e) {
		} catch (IllegalArgumentException e) {
		} catch (IllegalAccessException e) {
		} catch (InvocationTargetException e) {
		}
		
		return null;
	}
	
	public static Field createField(String name) {
		return new DefaultField(name);
	}
}